import { ATOM_NODE } from './graph'
import { Selection } from '@antv/x6-plugin-selection'
import { Snapline } from '@antv/x6-plugin-snapline'
import { Transform } from '@antv/x6-plugin-transform'
import { Scroller } from '@antv/x6-plugin-scroller'
import { MiniMap } from '@antv/x6-plugin-minimap'
import { History } from '@antv/x6-plugin-history'
import { Clipboard } from '@antv/x6-plugin-clipboard'
import { Keyboard } from '@antv/x6-plugin-keyboard'
import { EPluginKey, IDesignerOptions, IPlugin } from '@/types'

// 插件默认配置
export const PLUGINS: IPlugin = {
  [EPluginKey.SELECTION]: () => {
    return new Selection({
      enabled: true,
      multiple: true,
      rubberband: true,
      movable: true,
      showNodeSelectionBox: true,
      // pointerEvents: 'node',
      className: 'lfb-selection'
    })
  },
  [EPluginKey.SNAPLINE]: () => {
    return new Snapline({
      enabled: true,
      resizing: true
    })
  },
  [EPluginKey.TRANSFORM]: () => {
    return new Transform({
      resizing: {
        enabled: (node) => {
          return node.data.resize || false
        },
        minWidth: ATOM_NODE.width,
        minHeight: ATOM_NODE.height,
        orthogonal: false,
        // restrict: false,
        preserveAspectRatio: false,
        allowReverse: false
      }
    })
  },
  [EPluginKey.SCROLLER]: () => {
    return new Scroller({
      enabled: true,
      pageVisible: true,
      padding: 30
    })
  },
  [EPluginKey.MINIMAP]: (opts: IDesignerOptions) => {
    return new MiniMap({
      container: opts.container.miniMap,
      width: 200,
      height: 160,
      padding: 10
    })
  },
  [EPluginKey.HISTORY]: () => {
    return new History({
      enabled: true,
      beforeAddCommand: (event, args) => {
        // ports,组合的变化不记录，更具业务场景扩充此方法
        // const ignoreKeys = ['ports', 'children', 'parent']
        // return !ignoreKeys.includes(args?.)
      }
    })
  },
  [EPluginKey.CLIPBOARD]: () => {
    return new Clipboard({
      enabled: true
    })
  },
  [EPluginKey.KEYBOARD]: () => {
    return new Keyboard({
      enabled: true,
      global: false
    })
  }
}
